//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Galleries.Components;

namespace CommunityServer.ControlPanel.Galleries.Options
{
	/// <summary>
	///		Summary description for ImageSettings.
	/// </summary>
	public class ImageSettings : BaseGalleryControl
	{

		#region Public Properties

		public string ImageXClientID
		{
			get{return ImageX.ClientID;}
		}

		public string ImageYClientID
		{
			get{return ImageY.ClientID;}
		}

		#endregion

		#region Child Controls

		protected TextBox ImageX;
		protected RegularExpressionValidator Regularexpressionvalidator1;
		protected RequiredFieldValidator ImageXValidator;
		protected TextBox ImageY;
		protected RegularExpressionValidator Regularexpressionvalidator2;
		protected RequiredFieldValidator ImageYValidator;
		protected TextBox Quality;
		protected RegularExpressionValidator Regularexpressionvalidator3;
		protected RequiredFieldValidator QualityValidator;
		protected TextBox Brightness;
		protected RegularExpressionValidator RegularexpressionBrightnessValidator;
		protected RequiredFieldValidator BrightnessValidator;
		protected Panel BrightnessPanel;

		#endregion

		private void Page_Load(object sender, EventArgs e)
		{

		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new EventHandler(this.Page_Load);

		}
		#endregion

		public void SetFormFields(GalleryImageSettings settings)
		{

			ImageX.Text = settings.Width.ToString();
			ImageY.Text = settings.Height.ToString();
			Quality.Text = settings.Quality.ToString();
			Brightness.Text = settings.Brightness.ToString();

			BrightnessPanel.Visible = RegularexpressionBrightnessValidator.Enabled = BrightnessValidator.Enabled = (settings.GalleryImageType == GalleryImageType.Thumbnail);

			//we use the original placeholder for the max image size which can be -1
			if(settings.GalleryImageType == GalleryImageType.Original)
				Regularexpressionvalidator1.ValidationExpression = Regularexpressionvalidator2.ValidationExpression = "^[-]*[0-9]*";

		}

		public GalleryImageSettings GetFormFields()
		{
			GalleryImageSettings settings = new GalleryImageSettings(int.Parse(ImageX.Text), int.Parse(ImageY.Text),int.Parse(Quality.Text), true);
			
			if(settings.GalleryImageType == GalleryImageType.Thumbnail)
				settings.Brightness = int.Parse(Brightness.Text);

			return settings;
		}
	}
}
